package cn.tedu.luban.worker.main.repository;

import cn.tedu.luban.worker.main.converter.WorkerAuditConverter;
import cn.tedu.luban.worker.main.mapper.WorkerAuditLogMapper;
import cn.tedu.luban.worker.protocol.bo.AdminAuditBO;
import cn.tedu.luban.worker.protocol.dos.WorkerAuditLogDO;
import cn.tedu.luban.worker.protocol.param.AuditSubmitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class WorkerAuditLogRepository {

    @Autowired
    private WorkerAuditLogMapper workerAuditLogMapper;

    @Autowired
    private WorkerAuditConverter workerAuditConverter;


    public Long saveWorkerAudit(AuditSubmitParam auditSubmitParam) {

        //1.将param 转换成 DO对象
        WorkerAuditLogDO workerAuditLogDO = workerAuditConverter.param2do(auditSubmitParam);
        workerAuditLogMapper.insert(workerAuditLogDO);
        //利用mybatis回填新增id
        return workerAuditLogDO.getId();
    }

    public String getReason(Long userId) {
        List<WorkerAuditLogDO> workerAuditLogDOList=workerAuditLogMapper.selectRejectReasons(userId);
        WorkerAuditLogDO workerAuditLogDO = workerAuditLogDOList.get(0);
        return workerAuditLogDO.getRejectReason()+"["+workerAuditLogDO.getRemark()+"]";
    }

    public List<AdminAuditBO> getAuditLogs(Long userId) {
        List<WorkerAuditLogDO> dos=workerAuditLogMapper.selectWorkerAuditLogs(userId);
        return workerAuditConverter.dos2bos(dos);
    }
}
